package com.link.wseller.mapper;

import com.link.wseller.domain.ProductCategory;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface ProductCategoryMapper {
    @Delete({
        "delete from product_category",
        "where category_id = #{categoryId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer categoryId);

    @Insert({
        "insert into product_category (category_id, category_name, ",
        "category_type, create_time, ",
        "update_time)",
        "values (#{categoryId,jdbcType=INTEGER}, #{categoryName,jdbcType=VARCHAR}, ",
        "#{categoryType,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(ProductCategory record);

    @InsertProvider(type=ProductCategorySqlProvider.class, method="insertSelective")
    int insertSelective(ProductCategory record);

    @Select({
        "select",
        "category_id, category_name, category_type, create_time, update_time",
        "from product_category",
        "where category_id = #{categoryId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="category_id", property="categoryId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="category_name", property="categoryName", jdbcType=JdbcType.VARCHAR),
        @Result(column="category_type", property="categoryType", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    ProductCategory selectByPrimaryKey(Integer categoryId);

    @UpdateProvider(type=ProductCategorySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(ProductCategory record);

    @Update({
        "update product_category",
        "set category_name = #{categoryName,jdbcType=VARCHAR},",
          "category_type = #{categoryType,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where category_id = #{categoryId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ProductCategory record);
}